//
//  BodyDetailTool.m
//  PPScaleDemo
//
//  Created by 彭思远 on 2021/11/1.
//

#import "BodyDetailTool.h"

@interface BodyDetailTool ()
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *fatDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *visceralfatDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *metabolizeDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *watercontentDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *boneDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *proteinDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *bmiDetailModell;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *nofatWeightDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *obsLevelDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *subFatDetailModell;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *bodyAgeDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *bodyTypeDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *standardWeightDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *weightDetailMode;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *muscleDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *bodyScoreDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *bmdjDetailModel;
@property(nonatomic,strong,readwrite)PPBodyMeasureDetailModel *heartRateModel;
@property(nonatomic,strong,readwrite)PPBodyFatModel *originBody;

@end

@implementation BodyDetailTool

- (instancetype)initWithPPBodyFatModel:(PPBodyFatModel *)bodyData{
    if (self = [self init]) {
        self.originBody = bodyData;
        [self setAllInfoWithBodyData:bodyData];
    }
    return self;
}

- (void)setAllInfoWithBodyData:(PPBodyFatModel *)bodyData{
    // 脂肪
    self.fatDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BodyFat bodyData:bodyData];
    // 内脏脂肪
    self.visceralfatDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_VisFat bodyData:bodyData];
    // BMR
    self.metabolizeDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BMR bodyData:bodyData];
    // 水分
    self.watercontentDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_Water bodyData:bodyData];
    // 骨量
    self.boneDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_Bone bodyData:bodyData];
    // 蛋白质
    self.proteinDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_proteinPercentage bodyData:bodyData];
    // bmi
    self.bmiDetailModell = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BMI bodyData:bodyData];
    // 去脂体重
    self.nofatWeightDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BodyLBW bodyData:bodyData];
    // 肥胖等级
    self.obsLevelDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_FatGrade bodyData:bodyData];
    // 皮下脂肪
    self.subFatDetailModell = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BodySubcutaneousFat bodyData:bodyData];
    // 身体年龄
    self.bodyAgeDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_physicalAgeValue bodyData:bodyData];
    // 身体类型
    self.bodyTypeDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BodyType bodyData:bodyData];
    // 标准体重
    self.standardWeightDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_Bodystandard bodyData:bodyData];
    // 体重
    self.weightDetailMode = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_Weight bodyData:bodyData];
    // 肌肉
    self.muscleDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_Mus bodyData:bodyData];
    // 身体得分
    self.bodyScoreDetailModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_BodyScore bodyData:bodyData];

    self.heartRateModel = [[PPBodyMeasureDetailModel alloc] initWithBodyParam:PPBodyParam_heart bodyData:bodyData];
        
}


- (NSArray <BodyDetailModel *>*)flagBodyArr{

    
    NSMutableArray *arr = @[].mutableCopy;
    BodyDetailModel *weight = [self measureDetail2BodyDetail:self.weightDetailMode];
    weight.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppWeightKg] ;
    weight.unit = @"公斤";
    [arr addObject:weight];
    
    BodyDetailModel *BMI  = [self measureDetail2BodyDetail:self.bmiDetailModell];
    BMI .dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppBMI] ;
    BMI .unit = @"";
    [arr addObject:BMI];

    BodyDetailModel *BodyfatPercentage = [self measureDetail2BodyDetail:self.fatDetailModel];
    BodyfatPercentage.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppBodyfatPercentage] ;
    BodyfatPercentage.unit = @"公斤";
    [arr addObject:BodyfatPercentage];

    BodyDetailModel *MuscleKg = [self measureDetail2BodyDetail:self.muscleDetailModel];
    MuscleKg.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppMuscleKg] ;
    MuscleKg.unit = @"公斤";
    [arr addObject:MuscleKg];

    BodyDetailModel *WaterPercentage = [self measureDetail2BodyDetail:self.watercontentDetailModel];
    WaterPercentage.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppWaterPercentage] ;
    WaterPercentage.unit = @"%";
    [arr addObject:WaterPercentage];

    BodyDetailModel *flagVFAL = [self measureDetail2BodyDetail:self.visceralfatDetailModel];
    flagVFAL.dataVal = [NSString stringWithFormat:@"%ld", self.originBody.ppVFAL] ;
    flagVFAL.unit = @"";
    [arr addObject:flagVFAL];

    BodyDetailModel *BoneKg = [self measureDetail2BodyDetail:self.boneDetailModel];
    BoneKg.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppBoneKg] ;
    BoneKg.unit = @"公斤";
    [arr addObject:BoneKg];

    BodyDetailModel *BMR = [self measureDetail2BodyDetail:self.metabolizeDetailModel];
    BMR.dataVal = [NSString stringWithFormat:@"%ld", self.originBody.ppBMR] ;
    BMR.unit = @"Kcal";
    [arr addObject:BMR];

    BodyDetailModel *ProteinPercentage = [self measureDetail2BodyDetail:self.proteinDetailModel];
    ProteinPercentage.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppproteinPercentage] ;
    ProteinPercentage.unit = @"%";
    [arr addObject:ProteinPercentage];

    BodyDetailModel *VFPercentage = [self measureDetail2BodyDetail:self.subFatDetailModell];
    VFPercentage.dataVal = [NSString stringWithFormat:@"%.1f", self.originBody.ppBodySubcutaneousFat] ;
    VFPercentage.unit = @"%";
    [arr addObject:VFPercentage];

    BodyDetailModel *FatGrade = [self measureDetail2BodyDetail:self.obsLevelDetailModel];
    FatGrade.dataVal = [NSString stringWithFormat:@"%ld", self.originBody.ppFatGrade] ;
    FatGrade.unit = @"";
    [arr addObject:FatGrade];

    BodyDetailModel *BodyfatKg = [self measureDetail2BodyDetail:self.fatDetailModel];
    BodyfatKg.code = @"flagBodyfatKg";
    BodyfatKg.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppBodyfatKg] ;
    BodyfatKg.unit = @"公斤";
    [arr addObject:BodyfatKg];

    BodyDetailModel *LoseFatWeightKg = [self measureDetail2BodyDetail:self.nofatWeightDetailModel];
    LoseFatWeightKg.dataVal = [NSString stringWithFormat:@"%.2f", self.originBody.ppBodyLBW] ;
    LoseFatWeightKg.unit = @"公斤";
    [arr addObject:LoseFatWeightKg];

    BodyDetailModel *BodyAge = [self measureDetail2BodyDetail:self.bodyAgeDetailModel];
    BodyAge.dataVal = [NSString stringWithFormat:@"%ld", self.originBody.ppBodyAge] ;
    BodyAge.unit = @"岁";
    [arr addObject:BodyAge];

    BodyDetailModel *BodyType = [self measureDetail2BodyDetail:self.bodyTypeDetailModel];
    BodyType.dataVal = [NSString stringWithFormat:@"%ld", self.originBody.ppBodyType] ;
    BodyType.unit = @"";
    [arr addObject:BodyType];

    return arr;
}


- (BodyDetailModel *)measureDetail2BodyDetail:(PPBodyMeasureDetailModel *)m{
    
    BodyDetailModel *d = [[BodyDetailModel alloc] initWithPPBodyMeasureDetailModel:m];
    return d;
    
    
}



@end
